using System;
using System.ComponentModel;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsControlLibrary1
{
    public partial class ViewTables : UserControl
    {
        public ViewTables()
        {
            InitializeComponent();
        }
        #region myProperties
            private string strServer;
            private string strDatabase;
            private string strUID;
            private string strPWD;
                  
            public string Server
            {
                get { return strServer; }
                set { strServer = value; }
            }
            public string Database
            {
                get { return strDatabase; }
                set { strDatabase = value; }
            }
            public string UID
            {
                get { return strUID; }
                set { strUID = value; }
            }
            public string PWD
            {
                get { return strPWD; }
                set { strPWD = value; }
            }
        
        #endregion
        private void btnView_Click(object sender, EventArgs e)
        {
            ShowTable();
        }
        void Connection()
        {

        }
        void ShowTable()
        {                               
                string strCon = "server=" + strServer;
                strCon += ";database=" + strDatabase;
                strCon += ";uid=" + strUID;
                strCon += ";pwd=" + strPWD + ";";
                SqlConnection Con = new SqlConnection();
                Con.ConnectionString = strCon;
                SqlCommand Com;
                string strSQL = "select id,name,";
                strSQL += "crdate from sysobjects ";
                strSQL += " where xtype='U'";
                Com = new SqlCommand(strSQL, Con);
                try
                {
                    SqlDataReader dr;
                    Con.Open();
                    dr = Com.ExecuteReader();
                    ListViewItem item1;
                    while (dr.Read())
                    {
                        item1 = new ListViewItem(dr[0].ToString());
                        item1.SubItems.Add(dr[1].ToString());
                        item1.SubItems.Add(dr[2].ToString());
                        lvData.Items.Add(item1);
                    }

                    label1.Text = strDatabase;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        private void UserControl2_Load(object sender, EventArgs e)
        {
            lvData.Columns.Add("ID", 50, 0);
            lvData.Columns.Add("Name", 100, 0);
            lvData.Columns.Add("Date", 70, 0);
            lvData.View = View.Details;
        }
        }
}
